package com.cysion.study.presenter

import com.cysion.study.ktbox.base.BasePresenter
import com.cysion.study.ktbox.net.BaseResponseRx
import com.cysion.targetfun._subscribe
import com.cysion.study.helper.UserCache
import com.cysion.study.net.ApiClient
import com.cysion.study.ui.iview.RecharView

/**
 * Created by chu on 2019-06-30.
 */
class RecharPresenter : BasePresenter<RecharView>() {
    fun rechar( type: String) {
        checkViewAttached()
        attchedView?.loading()
        ApiClient.api.createOrder(UserCache.token,type).compose(BaseResponseRx.validateToMain())
            ._subscribe {
                _onNext {
                    attchedView?.stopLoad()
                    attchedView?.setUserInfo(it)
                }
                _onError {
                    attchedView?.stopLoad()
                    error(it)
                }
            }
    }

}